package com.bla.service.impl;

import com.bla.dao.myprojectdb.LeaderOrderDAO;
import com.bla.dao.myprojectdb.entity.LeaderOrderDO;
import com.bla.req.LeaderOrderRequest;
import com.bla.service.LeaderOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yzw
 * @date 2022/1/23 12:31
 * @desc
 */
@Service
public class LeaderOrderServiceImpl implements LeaderOrderService {

    @Resource
    private LeaderOrderDAO leaderOrderDAO;


    @Override
    public void insertOrder(LeaderOrderRequest request) {
        LeaderOrderDO leaderOrderDO = convert2LeaderOrderVO(request);
        leaderOrderDAO.insertOrder(leaderOrderDO);
    }



    @Override
    public Integer getVersionByOrderId(String orderId) {
        return leaderOrderDAO.getVersionByOrderId(orderId);
    }

    @Override
    public void updateOrderStatusByOrderId(LeaderOrderRequest request) {
        Integer version = leaderOrderDAO.getVersionByOrderId(request.getOrderId());
        LeaderOrderDO leaderOrderDO = convert2LeaderOrderVO(request);
        leaderOrderDO.setVersion(version);
        leaderOrderDAO.updateOrderStatus(leaderOrderDO);
    }

    private LeaderOrderDO convert2LeaderOrderVO(LeaderOrderRequest request) {
        LeaderOrderDO leaderOrderDO = new LeaderOrderDO();
        leaderOrderDO.setOrderId(request.getOrderId());
        leaderOrderDO.setOrderStatus(request.getOrderStatus());
        leaderOrderDO.setOrderAmount(request.getOrderAmount());
        return leaderOrderDO;
    }


}
